#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2020-08-27 09:37:13
# @Author  : Zuo Zhongfei (zuozhongfei@126.com)
# @Link    : www
# @Version : $Id$

import os

# 用0做除数，会引发崩溃：ZeroDivisionError
# print(5 / 0)

# 使用try-except代码块处理异常代码,避免程序崩溃
try:
    print(5 / 0)
except ZeroDivisionError as e:
    print("You can't divide by zero")


# FileNotFoundError 文件未找到异常
# with open('alice.txt') as file_object:
#     contents = file_object.read()

# 使用try-except处理异常

try:
    with open('alice.txt') as file_object:
        contents = file_object.read()
except FileNotFoundError as e:
    print("Sorry, the file does not exist")
else:
    print(contents)
